#include "kernel/types.h"
#include "user/user.h"

int main(int argc, char* argv[]) {
    //fork and wait
    int pid = fork();
    if (pid == 0) {
        printf("i am child process, pid: %d\n", pid);

        //for test, child process exit status 100
        exit(100);
    }

    else {
        //wait for child, print together will mess the console
        int childReturn;
        int childPid = wait(&childReturn);

        if (childPid == -1)
            printf("has no running children\n");
        
        else
            printf("wait for child: %d, return value: %d\n", childPid, childReturn);

        printf("i am main process, my child pid: %d\n", pid);

    }


    //exec
    char* argvec[] = {
        "echo",
        "hello",
        "world",
        0
    };

    int execReturn;
    if((execReturn = exec("echo", argvec)) == -1)
        printf("exec error\n");

    exit(0);
}